﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<long>" %>

<br class="CLEAR" />
<div class="EVENT_SHOPPING_LIST">
  <h1>已加入之組合商品　
    <input type="button" name="button" id="button" value="送出Send" onclick="addShoppingCart(<%:Model %>);" />
  </h1>
  <ul id="combolist">
  </ul>
  <br class="CLEAR" />
</div>

<script type="text/javascript">
    function getMIdList() {
        var midlist = [""];
        $('#combolist li input.mkguid').each(function () { midlist.push($(this).val()); });
        midlist.splice(0, 1);
        return midlist;
    }

    function getProductIdList() {
        var pidlist = [""];
        $('#combolist li input.pdguid').each(function () { pidlist.push($(this).val()); });
        pidlist.splice(0, 1);
        return pidlist;
    }

    function getSpecIdList() {
        var sidlist = [""];
        $('#combolist li input.specguid').each(function () { sidlist.push($(this).val()); });
        sidlist.splice(0, 1);
        return sidlist;
    }

    function addShoppingCart(comboid) {
        var jsonstring = {  
            "Mid":getMIdList(),
            "ProductId": getProductIdList(),
            "SpecId": getSpecIdList(),
            "comboid": comboid
        };
        $.ajax({
            type: "POST",
            traditional: true,
            url: "/api/combostc",
            data: jsonstring,
            dataType: "json",
            success: function (data) {
                if (data.code == "200") {
                    alert('加入購物車成功!!');
                    location.href = '/market/c';
                }
                else
                    alert(data.response);
            }
        });
    }
</script>